<?php

namespace JsonLowCode\Support;

/**
 * @property string $type  JSExpression|JSFunction|JSSlot
 * @property mixed $value
 * @property array $params [JSSlot|i18n]
 */
class JsParse extends Fluent
{
    /**
     * @param string $type
     */
    public function __construct(string $type = "JSExpression"|"JSFunction"|"JSSlot"|"JSBlock"|"i18n")
    {
        parent::__construct();
        $this->type = $type;
    }

    /**
     * @param mixed $value
     * @param mixed $extends
     * @return $this
     */
    public static function jsExpression(mixed $value, mixed $extends = []): static
    {
        $self = new self("JSExpression");
        $self->value = $value;
        if ($extends){
            $self->attributes = array_merge($self->attributes,$extends);
        }
        return $self;
    }

    /**
     * 设置JSFunction
     * @param mixed $value
     * @param array $params
     * @return $this
     */
    public static function jsFunction(mixed $value, array $params = []): static
    {
        $self = new self("JSFunction");
        $self->value = $value;
        if ($params){
            $self->params = $params;
        }
        return $self;
    }

    /**
     * 设置JSSlot
     * @param mixed $schema
     * @param array $params
     * @return static
     */
    public static function jsSlot(mixed $schema = null, array $params = []): static
    {
        $self = new self("JSSlot");
        $self->value = $schema;
        if ($params){
            $self->params = $params;
        }
        return $self;
    }
}
